package com.itcam.tingshu.search.api;

import com.itcam.tingshu.common.result.Result;
import com.itcam.tingshu.model.album.AlbumAttributeValue;
import com.itcam.tingshu.model.search.AlbumInfoIndex;
import com.itcam.tingshu.query.search.AlbumIndexQuery;
import com.itcam.tingshu.query.search.AlbumIndexQuery;
import com.itcam.tingshu.search.service.SearchService;
import com.itcam.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;


    /**
     * 专辑上架
     * @param albumId
     * @return
     */
    @Operation(summary = "专辑上架")
    @GetMapping("/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId) {
        //  调用服务层方法
        searchService.upperAlbum(albumId);
        //  返回数据
        return Result.ok();
    }

    /**
     * 专辑下架
     * @param albumId
     * @return
     */
    @Operation(summary = "专辑下架")
    @GetMapping("/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId) {
        //  调用服务层方法
        searchService.lowerAlbum(albumId);
        //  返回数据
        return Result.ok();
    }

    /**
     * 批量上架
     * @return
     */
    @Operation(summary = "批量上架")
    @GetMapping("batchUpperAlbum")
    public Result batchUpperAlbum(){
        //  循环
        for (long i = 1; i <= 1500; i++) {
            searchService.upperAlbum(i);
        }
        //  返回数据
        return Result.ok();
    }

    /**
     * 检索 result.data.list result.data.total;
     * 前端渲染 v-for
     * @param albumIndexQuery
     * @return
     */
    @Operation(summary = "检索")
    @PostMapping
    public Result search(@RequestBody AlbumIndexQuery albumIndexQuery){
        //  调用服务层方法.
        AlbumSearchResponseVo searchResponseVo = searchService.search(albumIndexQuery);
        //  返回数据
        return Result.ok(searchResponseVo);
    }

    /**
     * 获取频道页数据 —— 根据一级分类Id获取数据
     * @param category1Id
     * @return
     */
    @Operation(summary = "获取频道页数据")
    @GetMapping("channel/{category1Id}")
    public Result channel(@PathVariable Long category1Id){
        //  调用服务层方法
        List<Map<String,Object>> list = searchService.channel(category1Id);
        //  返回数据
        return Result.ok(list);
    }

    /**
     * 自动补全功能
     * @param keyword
     * @return
     */
    @Operation(summary = "关键字自动补全")
    @GetMapping("completeSuggest/{keyword}")
    public Result completeSuggest(@PathVariable String keyword){
        //  调用服务层方法
        List<String> list = this.searchService.completeSuggest(keyword);
        //  返回数据.
        return Result.ok(list);
    }

    /**
     * 查看排行榜
     * @param category1Id
     * @param dimension
     * @return
     */
    @Operation(summary = "查看排行榜")
    @GetMapping("/findRankingList/{category1Id}/{dimension}")
    public Result findRankingList(@PathVariable Long category1Id, @PathVariable String dimension){
        //  调用服务层方法
        List<AlbumInfoIndex> albumInfoIndexList = searchService.findRankingList(category1Id,dimension);
        //  返回数据
        return Result.ok(albumInfoIndexList);
    }

    /**
     * 手动调用排行榜
     * @return
     */
    @Operation(summary = "手动调用排行榜")
    @GetMapping("updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking(){
        //  调用服务层方法.
        searchService.updateLatelyAlbumRanking();
        //  返回数据
        return Result.ok();
    }


}

